<?php
require_once('functions.php');

// ORDERITEMS FUNCTIONS
function GetOIs(){
	$conn = GetConnection();
	return $results = $conn -> query('SELECT * FROM WSP2012_OrderItems');
}

function GetOI($id){
	$conn= GetConnection();
	$sql = "SELECT * FROM WSP2012_OrderItems WHERE orderitems_id=$id ";
	$results = $conn -> query($sql);
	$row = $results -> fetch_assoc();
	$conn -> close();
	return $row;
}

function SaveOI($row){
	$conn = GetConnection();
	$row2 = EscapeRow($row, $conn);
	$sql = "UPDATE `WSP2012_OrderItems` " 
		.	"Set order_id='$row2[order_id]', products_id='$row2[products_id]', updated_at='$row2[updated_at]', quantity='$row2[quantity]', "
		.	"quantity_price='$row2[quantity_price]' " 	
		.	"WHERE orderitems_id='$row2[id]' ";
	$results = $conn -> query($sql);
	$error = $conn -> error;
	$conn -> close();
	
	return $error == '' ? true : array('SQL Error' => $error);	
}

function CreateOI($row){
	$conn = GetConnection();
	$row2 = EscapeRow($row, $conn);
	$sql = "INSERT INTO `WSP2012_OrderItems` "
		.		"(orderitems_id, order_id, products_id, created_at, updated_at, quantity, quantity_price) "
		.		"VALUES ('$row2[orderitems_id]', '$row2[order_id]', '$row2[products_id]', '$row2[created_at]', '$row2[updated_at]', '$row2[quantity]', '$row2[quantity_price]') ";
	$results = $conn -> query($sql);
	$error = $conn -> error;
	$conn -> close();	
	
	return $error == '' ? true : array('SQL Error' => $error);
}

function DeleteOI($row, $id){
	$conn = GetConnection();
	$row2 = EscapeRow($row, $conn);
	$sql = "DELETE from WSP2012_OrderItems WHERE orderitems_id= '$row2[id]' ";
	$results = $conn -> query($sql);
	$error = $conn -> error;
	$conn -> close();	
	
	return $error == '' ? true : array('SQL Error' => $error);
}
?>
